package com.yanqu.road.dao.impl.activity.recoveryReward;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.retrievereward.config.RecoveryRewardParameterConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class RecoveryRewardParameterConfigDaoImpl extends TempDao {
    private static String getRecoveryRewardParameterConfigSql = "select * from `t_s_activity_recovery_item` where `activityId`=?";
    public Map<Integer,RecoveryRewardParameterConfig> getRecoveryRewardParameterConfigMap(int activityId) {
        Map<Integer,RecoveryRewardParameterConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getRecoveryRewardParameterConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                RecoveryRewardParameterConfig recoveryRewardParameterConfig = new RecoveryRewardParameterConfig();
                recoveryRewardParameterConfig.setActivityId(rs.getInt("activityId"));
                recoveryRewardParameterConfig.setId(rs.getInt("id"));
                recoveryRewardParameterConfig.setDiscountParameter(rs.getInt("discountParameter"));
                map.put(recoveryRewardParameterConfig.getId(),recoveryRewardParameterConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }
}